import type { Effect, Reducer } from 'umi';
import { getPaperDetail } from '@/services/paper';

export type QuestionModelType = {
  namespace: 'question';
  state: QuestionModelState;
  effects: {
    getInfo: Effect;
  };
  reducers: {
    changeQuestion: Reducer<QuestionModelState>;
  };
};

export type QuestionModelState = {
  select_list: request.SelectType[];
};

const QuestionModel: QuestionModelType = {
  namespace: 'question',
  state: {
    select_list: [],
  },
  effects: {
    *getInfo({ payload }, { call, put }) {
      const response = yield call(getPaperDetail, { paper_id: +payload.paper_id });
      yield put({
        type: 'changeQuestion',
        payload: response,
      });
    },
  },
  reducers: {
    changeQuestion(state, { payload }) {
      return {
        ...state,
        ...payload.data,
      };
    },
  },
};
export default QuestionModel;
